package com.gzz.orchid.main.facade;

import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;

/**
 * @author higmd
 */
@Slf4j
@SpringBootApplication(scanBasePackages = {
        "com.gzz.orchid.context.infrastructure.configuration"
        , "com.gzz.orchid.main.facade"
})
@MapperScan("com.gzz.orchid.context.infrastructure.persistence")
@EnableAutoConfiguration
public class FacadeApplication {
    public static void main(String[] args) {

        var appContext = SpringApplication.run(FacadeApplication.class, args);
        // 自动配置诊断
        appContext.getBean(ConditionEvaluationReport.class)
                .getConditionAndOutcomesBySource()
                .forEach((k, v) -> {
                    //System.out.println("@-@=> " + k + " => " + v);
                });

    }

    // 定义一个 Bean，类型为 CommandLineRunner，在 Spring Boot 应用启动完成后执行
    //    @Bean
    //    public CommandLineRunner conditionReport(ApplicationContext appContext) {
    //        log.info("facade application started");
    //        return args -> {
    //            ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) appContext.getParentBeanFactory();
    //            // 获取条件评估报告，通过应用上下文的 Bean 工厂来获取
    //            ConditionEvaluationReport report = ConditionEvaluationReport.get(beanFactory);
    //            // 遍历条件评估报告中按源分组的条件和结果，并打印输出
    //            report.getConditionAndOutcomesBySource().forEach((k, v) -> {
    //                System.out.println(k + " => " + v);
    //            });
    //        };
    //    }
    @PreDestroy
    public void destroy() {
        log.error("Application is destroyed。。。。销毁。");
    }
}